package tom.jiafei;
import java.sql.*;
import java.io.*;
public class UserInf{
	String uid="",passward,shoppingList;
	String[] userInf={"1","2","3","4","5","6","7"};
	boolean whetherMatch=false;
	public void setUid(String s){
		uid=s.trim();
	}
	public String getUid(){
		return uid;
	}
	public void setPassward(String s){
		passward=s;
	}
	public String getPassward(){
		return passward;
	}
	public void setWhetherMatch(){
		String str=userInf[2].trim();
		if(passward.equals(str)){
			whetherMatch=true;
		}

	}
	public boolean getWhetherMatch(){
		return whetherMatch;
	}
	public void setUserInf(){
		Connection con;
	    Statement sql;
	    ResultSet rs;
	    try{
	    	Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
	    	}
	    catch(Exception e){userInf[0]="300";}
   
    try{
		String uri = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=book_store";
		String user = "sa";
		String password = "sa";
		con=DriverManager.getConnection(uri,user,password);
		sql=con.createStatement();
		rs=sql.executeQuery("SELECT * from user_ where userid="+"'"+uid+"'");
		if(rs.next()){
			for(int i=0;i<7;i++){
				userInf[i]=rs.getString(i+1);
			}			
		}
		con.close();
	}
	catch(SQLException e1){userInf[2]="100";}
	}
	public String[] getUserInf(){
		return userInf;
	}
	public String getShoppingList(){
		return userInf[6];
	}
	
}